package net.jueb.server;
import java.net.InetSocketAddress;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;
import io.netty.util.CharsetUtil;

public class UdpServerHandler extends SimpleChannelInboundHandler<DatagramPacket>{

	protected void messageReceived(ChannelHandlerContext ctx,DatagramPacket data) throws Exception {
		String msg=data.content().toString(CharsetUtil.UTF_8);
		InetSocketAddress sender=data.sender();
		System.out.println("收到来自"+sender+"的UPD数据:"+msg);
		
		ByteBuf response=Unpooled.copiedBuffer("Hello Client!".getBytes(CharsetUtil.UTF_8));
		ctx.writeAndFlush(new DatagramPacket(response,sender));
	}
}
